package JDBCDemo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;



public class JDBCDemo {
	
	public static void update() throws ClassNotFoundException, SQLException{
		//设置端口、库名和密码
		String url = "jdbc:mysql://localhost:3306/manager";
		String username = "student";
		String password = "st_123456";
	
		PreparedStatement statement=null;  //实现功能，增删改查，SQL语句
		ResultSet rs=null;
		try{
			//加载驱动	Class.forName("com.mysql.jdbc.Driver");
			Class.forName("com.mysql.jdbc.Driver");
			
			//建立数据库连接
			Connection connection=  DriverManager.getConnection(url,username,password); 
			Statement stmt=connection.createStatement();
//			String sql="insert into t_hero(name,id,level) values(?,?,?)";  
			String sql="select name,id level from t_hero";
			rs=stmt.executeQuery(sql);
			while(rs.next()) {
				String sname=rs.getString("name");
				System.out.println(sname);
			}
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (SQLException e) {
			e.printStackTrace();
		}finally {
			if(statement!=null) {
				try {
					statement.close();
				}catch(SQLException e)
				{
					
				}
			}
			
		}
		
	}
	
	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		
		update();
		System.out.println("sname");
	}
	
}